package com.blb.permission_ms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blb.permission_ms.entity.Permission;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionMapper extends BaseMapper<Permission> {

    /**
     * 按pid查询子权限
     * @param pid
     * @return
     */
    @Select("select * from permission where pid = #{pid}")
    List<Permission> selectPermissionsByPid(Long pid);

    /**
     * 查询所有权限树
     * @return
     */
    @ResultMap("com.blb.permission_ms.mapper.UserMapper.permissionMap")
    @Select("select * from permission where pid = 1")
    List<Permission> selectPermissionsTree();

    /**
     * 通过角色id查询出所有权限的id
     * @param roleId
     * @return
     */
    @Select("select permission_id from role_permission where role_id = #{roleId}")
    List<Long> selectPermissionIdsByRoleId(Long roleId);
}
